package com.cy.rsspush;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class RssScheduler {

    // 定时任务：每分钟抓取一次 RSS 数据
    public static class FetchRssJob implements Job {
        @Override
        public void execute(JobExecutionContext context) throws JobExecutionException {
            RssReader rssReader = new RssReader();
            String rssUrl = "https://www.shrm.org/ResourcesAndTools/rss";  // 你可以替换成你需要订阅的 RSS 源链接
            rssReader.readRssFeed(rssUrl);
        }
    }

    public static void main(String[] args) throws SchedulerException {
        // 创建 JobDetail
        JobDetail job = JobBuilder.newJob(FetchRssJob.class)
                .withIdentity("rssJob", "group1")
                .build();

        // 创建触发器，每分钟触发一次
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "group1")
                .startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInMinutes(1)  // 每分钟执行一次
                        .repeatForever())
                .build();

        // 创建调度器
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.start();

        // 将任务和触发器注册到调度器
        scheduler.scheduleJob(job, trigger);
    }
}
